<div class="mdui-card-header">
    <button type="button" id="addBtn" class="ml10 mdui-btn mdui-btn-raised mdui-btn-dense mdui-btn-icon" title="添加" onclick="add()"><i class="mdui-icon material-icons">add</i></button>
</div>

<div class="mdui-card-content">
    <#if dataList?? && (dataList?size > 0)>
        <div class="mdui-table-fluid">
            <table class="mdui-table">
                <thead>
                <tr>
                    <th>用户名</th>
                    <th>手机号</th>
                    <th>用户类型</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <#list dataList as obj>
                    <tr>
                        <td>${obj.userName!}</td>
                        <td>${obj.phone!}</td>
                        <td>${obj.userType!}</td>
                        <td>${obj.createTime!?string('yyyy-MM-dd HH:mm::ss')}</td>
                        <td>
                            <button onclick="edit('${obj.id!}')" type="button" class="mdui-btn mdui-btn-raised mdui-btn-dense mdui-btn-icon" title="编辑"><i class="mdui-icon material-icons">&#xe3c9;</i></button>
                            <button onclick="del('${obj.id!}','${obj.name!}')" type="button" class="ml10 mdui-btn mdui-btn-raised mdui-btn-dense mdui-btn-icon" title="删除"><i class="mdui-icon material-icons">&#xe872;</i></button>
                            <button onclick="resetPwd('${obj.id!}','${obj.name!}')" type="button" class="ml10 mdui-btn mdui-btn-raised mdui-btn-dense mdui-btn-icon" title="重置用户密码"><i class="mdui-icon material-icons">&#xe869;</i></button>
                        </td>
                    </tr>
                </#list>
                </tbody>
            </table>
        </div>
    <#else>
        <b>暂无用户信息</b>
    </#if>
</div>

<script>
    function edit(id) {
        loadPost("user/editIndex", 'id=' +id, "#myContent", true);
    }

    function add() {
        loadPost("user/addIndex", '', "#myContent", true);
    }
    
    function del(id,name) {
        mdui.confirm('是否删除'+ name,
            function(){
                loadPost("user/del", 'id=' + id, "#myContent", false);
            },
            function(){

            }
        );
    }

    function resetPwd(id,name) {
        mdui.confirm('是否重置用户'+ name + "的登录密码",
           function () {
               $.ajax({
                   url:"user/resetPwd",
                   data:'id=' + id,
                   sync:false,
                   dataType:'json',
                   success:function (res) {
                       alert(res.data);
                   },
                   error:function (res) {
                       alert(res.data);
                   }
               })
           }
        );
    }
</script>
